/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.pod.hoteishilton.control;

import edu.pod.hoteishilton.dao.IDAOHospede;
import edu.pod.hoteishilton.model.Hospede;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


/**
 *
 * @author Tigaz
 */
//public class HospedeControl extends UnicastRemoteObject implements IHospedeControl{
public class HospedeControl {
    protected static IDAOHospede daoHospede;
    
    public HospedeControl(IDAOHospede dao) throws RemoteException{
        if(daoHospede == null){
            daoHospede = dao;
        }
    }

    public void addHospede(Hospede h) throws RemoteException{

        //TESTEEEE
        
        
        //Qual sera a chave?? nao seria bom ter CPF?? ai procurariamos o Hospede pelo CPF dele...
        Hospede h2 = daoHospede.getHospede(h.getCpf());
        
        if(h2 == null){
            daoHospede.persist(h);
        }
        else{
            h2.setEmail(h.getEmail());
            h2.setEndereco(h.getEndereco());
            h2.setNome(h.getNome());
            h2.setTelefone(h.getTelefone());
            h2.setUltimaHospedagem(h.getUltimaHospedagem());
            
            daoHospede.merge(h2);
        }
    }

    public HashMap getHospedes() throws RemoteException {
        return daoHospede.getHospedes();
    }

    public Hospede getHospede(String cpf) throws RemoteException {
        return daoHospede.getHospede(cpf);
    }
    
}
